(function ($) {
	AjaxSolr.RulerWidget = AjaxSolr.AbstractWidget.extend({
		rules: {
			"location": [ ],
			"target": [ {
				"name": "Proteins",
	             "action": [
	    	                 {name:"Highlight",type:"single"},
	    	                 {name:"Show",type:"single"},
	    	                 {name:"Hide",type:"single"},
	    	                 {name:"Color",type:"color"},
	    	                 {name:"Border",type:"color"},
	    	                 {name:"Color By",type:"select",options:["Protein Queried","Functional Class","Organism","Gene Name"]},
	    	                 {name:"Border By",type:"select",options:["Protein Queried","Functional Class","Organism","Gene Name"]},
	    	                 {name:"Show Label",type:"select",options:["ID","Functional Class","Organism","Gene Name"]},
	    	                 {name:"Hide Label",type:"single"}
	    	             ],
				"conditions": [ {
					"name": "interactions with",
					"type": "selects",
					"amount": 1,
					"values": [ ]
				}, {
					"name": "number of interactions",
					"type": "numeric_comparison"
				}, {
					"name": "accession number",
					"type": "text_comparison"
				}, {
					"name": "feature",
					"type": "feature_comparison",
					"values": [ ]
				}, {
					"name": "no rules at all",
					"type": "all"
				} ]
			}, {
				"name": "Interactions",
	             "action": [
	    	                 {name:"Highlight",type:"single"},
	    	                 {name:"Show",type:"single"},
	    	                 {name:"Hide",type:"single"},
	    	                 {name:"Color",type:"color"}
	    	             ],
				"conditions": [ {
					"name": "protein",
					"type": "selects",
					"amount": 1,
					"values": [ ]
				}, {
					"name": "proteins",
					"type": "selects",
					"amount": 2,
					"values": [ ]
				}, {
					"name": "score",
					"type": "numeric_comparison"
				}, {
					"name": "type of evidence",
					"type": "selects",
					"amount": 1,
					"values": [ "neighborhood" ,"fusion", "cooccurrence","txt_mining","microarray","similarity","domain","experimental","knowledge","pdb","interlogs"]
				}, {
					"name": "no rules at all",
					"type": "all"
				} ]
			} ]
		},
		ruler:null,
		init: function(){
			var self=this;
			self.rules.target[0].conditions[3].values=self.manager.widgets["graph"].orderProteinFeatures;
			self.ruler = new Biojs.Ruler({
				target: "ruler",
				allowOrdering:true,
				rules: self.rules
			});	

			self.ruler.onRuleCreated(function( objEvent ) {
				self.manager.widgets["graph"].executeStylers();
			}); 
			self.ruler.onRuleRemoved(function( objEvent ) {
				self.manager.widgets["graph"].executeStylers();
			}); 
			self.ruler.onRuleEditing(function( objEvent ) {
				self.manager.widgets["graph"].executeStylers();
			}); 
			self.ruler.onOrderChanged(function( objEvent ) {
				self.manager.widgets["graph"].executeStylers();
			}); 
		},
		afterRequest: function () {
			var self = this;
			var visibleProteins=[];
			if (typeof this.manager.response.responseHeader.params.q != 'undefined')
				visibleProteins = Object.keys(self.manager.widgets["graph"].graph.proteinsA);
			self.rules.target[0].conditions[0].values=visibleProteins;
			self.rules.target[1].conditions[0].values=visibleProteins;
			self.rules.target[1].conditions[1].values=visibleProteins;
		}
	});
})(jQuery);